//
//  Admin_VC.m
//  K-Music
//
//  Created by CHUN on 16/6/2.
//  Copyright © 2016年 CHUN. All rights reserved.
//

#import "Admin_area_VC.h"
#import "Admin_area_mode.h"


@interface Admin_area_VC ()

@property (nonatomic ,strong) UITableView * QUYU_TableView;

@end

@implementation Admin_area_VC

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.view.backgroundColor = RGB(241, 241, 241);
    
    self.navigationItem.title = @"地区选择";
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"back" highIcon:@"back" target:self action:@selector(back_back)];
    
    [self creatUI];
    
}

- (void)back_back
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -creatUI-
- (void)creatUI
{
    self.QUYU_TableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT+49) style:UITableViewStylePlain];
    self.QUYU_TableView.delegate = self;
    self.QUYU_TableView.dataSource =self;
    self.QUYU_TableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.QUYU_TableView.backgroundColor = RGB(241, 241, 241);
    [self.view addSubview:self.QUYU_TableView];
    
}

#pragma mark -UITableViewDataSource-

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [User_information conversion].admin_area.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *cellID = @"cellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    
    Admin_area_mode * data = [[Admin_area_mode alloc]init];
    
    data = [[User_information conversion].admin_area objectAtIndex:indexPath.row];
    
    if (cell == nil) {
        
         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
    }

    cell.textLabel.text = data.city;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    Admin_area_mode * data = [[Admin_area_mode alloc]init];
    
    data = [[User_information conversion].admin_area objectAtIndex:indexPath.row];
    
    [User_information conversion].area_city = data.city;
    [User_information conversion].adminAreaCode = data.adminAreaCode ;
    
    [tableView deselectRowAtIndexPath:tableView.indexPathForSelectedRow animated:YES];

    [self back_back];

}


@end
